home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / j109lxa4.tar / global.h < prev    next >
C/C++ Source or Header  |  1994-06-04  |  11KB  |  412 lines

  1. #ifndef _GLOBAL_H
  2. #define _GLOBAL_H
  3.  
  4. #if defined(__cplusplus) || defined(__STDC__)
  5. #define PROTOTYPES 1
  6. #endif
  7.  
  8. #ifdef __cplusplus
  9. #define private j_private
  10. #define public j_public
  11. #define protected j_protected
  12. #define class j_class
  13. #define virtual j_virtual
  14. #define new j_new
  15. #define delete j_delete
  16. #define friend j_friend
  17. #endif
  18.  
  19. /* Global definitions used by every source file.
  20.  * Some may be compiler dependent.
  21.  */
  22.  
  23. #if     defined(__TURBOC__) || defined(__STDC__) || defined(LATTICE)
  24. #define ANSIPROTO       1
  25. #endif
  26.  
  27. #ifdef UNIX
  28. #define O_BINARY 0
  29. #define cdecl
  30. #define _Cdecl
  31. #define far
  32. #define _FAR
  33. #define near
  34. #define _NEAR
  35. #endif
  36.  
  37. /* Distinguish between Turbo C 2.0, and TC++ v1.0 and Borland C++ 2.0,3.0,3.1 */
  38. #if defined(__TURBOC__) && __TURBOC__ >= 0x0295 && __TURBOC__ < 0x0300
  39. #define __BORLANDC__ 0x0100     /* Pretend we're Borland C */
  40. /* Turbo C++ 1.0x is confused about some structures whose addresses are
  41.     passed as arguments.  We kludge something here to fix it...wa7tas
  42.     We use "-stu" to ignore the Warning: Undefined structure 'xxx' messages.
  43. */
  44. #pragma warn -stu
  45. extern struct ax25_cb;
  46. extern struct iface;
  47. extern struct ip;
  48. extern struct mbx;
  49. extern struct mbuf;
  50. extern struct nr4cb;
  51. extern struct session;
  52. #endif
  53.  
  54. /* Distinguish between Turbo C 2.0, and Borland C++ 2.0,3.0,3.1 */
  55. #if defined(__TURBOC__) && defined(__BORLANDC__)
  56. #define DFAR far
  57. #else
  58. #define DFAR
  59. #endif
  60.  
  61. #ifndef __ARGS
  62. #ifdef  ANSIPROTO
  63. #define __ARGS(x)       x
  64. #ifdef __GNUC__
  65. #define __FARGS(x) x
  66. #else
  67. #define __FARGS(x) ()
  68. #endif
  69. #else
  70. #define __ARGS(x)       ()
  71. #define __FARGS(x) ()
  72. #endif
  73. #endif
  74.  
  75. /* To avoid some problems with the possibility of opening devices
  76.  * that lock up nos (ie. CON etc.)
  77.  * redefine fopen() call.
  78.  * WG7J, 930205
  79.  */
  80. #ifndef _STDIO_H
  81. #include <stdio.h>
  82. #endif
  83. #ifndef UNIX
  84. FILE _FAR *_Cdecl newfopen(const char _FAR *__path, const char _FAR *__mode);
  85. #define fopen newfopen
  86. #endif
  87.  
  88. #if     !defined(AMIGA) && (defined(LATTICE) || defined(MAC) || defined(__TURBOC__))
  89. /* These compilers require special open modes when reading binary files.
  90.  *
  91.  * "The single most brilliant design decision in all of UNIX was the
  92.  * choice of a SINGLE character as the end-of-line indicator" -- M. O'Dell
  93.  *
  94.  * "Whoever picked the end-of-line conventions for MS-DOS and the Macintosh
  95.  * should be shot!" -- P. Karn's corollary to O'Dells' declaration
  96.  */
  97. #define READ_BINARY     "rb"
  98. #define WRITE_BINARY    "wb"
  99. #define APPEND_BINARY   "ab+"
  100. #define READ_TEXT       "rt"
  101. #define WRITE_TEXT      "wt"
  102. #define APPEND_TEXT     "at+"
  103.  
  104. #else
  105.  
  106. #define READ_BINARY     "r"
  107. #define WRITE_BINARY    "w"
  108. #define APPEND_BINARY   "a+"
  109. #define READ_TEXT       "r"
  110. #define WRITE_TEXT      "w"
  111. #define APPEND_TEXT     "a+"
  112.  
  113. #endif
  114.  
  115. /* These two lines assume that your compiler's longs are 32 bits and
  116.  * shorts are 16 bits. It is already assumed that chars are 8 bits,
  117.  * but it doesn't matter if they're signed or unsigned.
  118.  */
  119. typedef long int32;             /* 32-bit signed integer */
  120. typedef unsigned short int16;   /* 16-bit unsigned integer */
  121. typedef unsigned char byte_t;   /*  8-bit unsigned integer */
  122. #define uchar(x) ((unsigned char)(x))
  123. #define MAXINT16 65535          /* Largest 16-bit integer */
  124. #ifdef __GNUC__
  125. #define MAXINT32 4294967295UL    /* Largest 32-bit integer */
  126. #else
  127. #define MAXINT32 4294967295L    /* Largest 32-bit integer */
  128. #endif
  129.  
  130. #define HASHMOD 7               /* Modulus used by hash_ip() function */
  131.  
  132. /* The "interrupt" keyword is non-standard, so make it configurable */
  133. #if     defined(__TURBOC__) && defined(MSDOS)
  134. #define INTERRUPT       void interrupt
  135. #else
  136. #define INTERRUPT       void
  137. #endif
  138.  
  139. /* Note that these definitions are on by default if none of the Turbo-C style
  140.  * memory model definitions are on; this avoids having to change them when
  141.  * porting to 68K environments.
  142.  */
  143. #if     !defined(__TINY__) && !defined(__SMALL__) && !defined(__MEDIUM__)
  144. #define LARGEDATA       1
  145. #endif
  146.  
  147. #if     !defined(__TINY__) && !defined(__SMALL__) && !defined(__COMPACT__)
  148. #define LARGECODE       1
  149. #endif
  150.  
  151. /* Since not all compilers support structure assignment, the ASSIGN()
  152.  * macro is used. This controls how it's actually implemented.
  153.  */
  154. #ifdef  NOSTRUCTASSIGN  /* Version for old compilers that don't support it */
  155. #define ASSIGN(a,b)     memcpy((char *)&(a),(char *)&(b),sizeof(b));
  156. #else                   /* Version for compilers that do */
  157. #define ASSIGN(a,b)     ((a) = (b))
  158. #endif
  159.  
  160. /* Define null object pointer in case stdio.h isn't included */
  161. #ifndef NULL
  162. /* General purpose NULL pointer */
  163. #define NULL (void *)0
  164. #endif
  165. #define NULLCHAR (char *)0      /* Null character pointer */
  166. #define NULLCHARP (char **)0    /* Null character pointer pointer */
  167. #define NULLINT (int *)0        /* Null integer pointer */
  168. #ifdef __GNUC__
  169. #define NULLFP(x)  (int (*)x)0
  170. #define NULLVFP(x) (void (*)x)0
  171. #else
  172. #define NULLFP(x)  (int (*)())0   /* Null pointer to function returning int */
  173. #define NULLVFP(x) (void (*)())0  /* Null pointer to function returning void */
  174. #endif
  175. #define NULLVIFP (INTERRUPT (*)())0
  176. #define NULLFILE (FILE *)0      /* Null file pointer */
  177.  
  178. /* standard boolean constants */
  179. #define FALSE 0
  180. #define TRUE 1
  181. #define NO 0
  182. #define YES 1
  183.  
  184. #ifdef UNIX
  185. #ifdef BSD_RANDOM
  186. #define SRANDOM(n) srandom(n)
  187. #define RANDOM(n) ((int) (random() * (n)))
  188. #else
  189. #define SRANDOM(n) srand48(n)
  190. #define RANDOM(n) ((int) (drand48() * (n)))
  191. #endif
  192. #else
  193. #define RANDOM(n) random(n)
  194. #endif
  195.  
  196. #ifdef UNIX
  197. /* !@#$%&* DOS quote-C-unquote dialects! ++bsa */
  198. #define strcmpi strcasecmp
  199. #define stricmp strcasecmp
  200. #define strncmpi strncasecmp
  201. #define strnicmp strncasecmp
  202. /* and work around a collision which is currently making me drop core... */
  203. #define tputs j_tputs
  204. /* some older systems lack strtoul(); we'll just have to hope this is okay */
  205. #ifdef NO_STRTOUL
  206. #define strtoul(s,cp,b) ((unsigned long) strtol((s),(cp),(b)))
  207. #endif
  208. /* minimal malloc checking is done, so intercept free() */
  209. #define free j_free
  210. #endif
  211.  
  212. /* string equality shorthand */
  213. #define STREQ(x,y) (strcmp(x,y) == 0)
  214.  
  215. /* Extract a short from a long */
  216. #define hiword(x)       ((int16)((x) >> 16))
  217. #define loword(x)       ((int16)(x))
  218.  
  219. /* Extract a byte from a short */
  220. #define hibyte(x)       ((unsigned char)((x) >> 8))
  221. #define lobyte(x)       ((unsigned char)(x))
  222.  
  223. /* Extract nibbles from a byte */
  224. #define hinibble(x)     (((x) >> 4) & 0xf)
  225. #define lonibble(x)     ((x) & 0xf)
  226.  
  227.   
  228. #ifdef UNIX
  229. /* Unix doesn't need x86 cruft */
  230. #define MK_FP(seg,off) ((void *) (seg))
  231. #define FP_SEG(p) ((unsigned long) (p))
  232. #endif
  233.  
  234.   /* Various low-level and miscellaneous functions */
  235. #ifdef UNIX
  236. /* internal functions that must be hidden */
  237. #define alarm j_alarm
  238. #define pause j_pause
  239. #endif
  240. #if 0
  241. int tcmdprintf __ARGS((const char *, ...))
  242. #ifdef __GNUC__
  243.     __attribute__ ((format (printf, 1, 2)))
  244. #endif
  245.     ;
  246. #ifdef fileno
  247. int traceprintf __ARGS((FILE *,const char *,...))
  248. #ifdef __GNUC__
  249.     __attribute__ ((format (printf, 2, 3)))
  250. #endif
  251.     ;
  252. int tfprintf __ARGS ((FILE *,const char *,...))
  253. #ifdef __GNUC__
  254.     __attribute__ ((format (printf, 2, 3)))
  255. #endif
  256.     ;
  257. #endif
  258. #endif
  259. #ifndef UNIX
  260. unsigned long availmem __ARGS((void));
  261. #endif
  262. void *callocw __ARGS((unsigned nelem,unsigned size));
  263. int32 clock __ARGS((void));
  264. int dirps __ARGS((void));
  265. #ifdef UNIX
  266. #define getopt j_getopt
  267. /* not sure how NOS will work with the GNU one... */
  268. #endif
  269. int getopt __ARGS((int argc,char *argv[],char *opts));
  270. int atoip __ARGS((char *));
  271. int htoi __ARGS((char *));
  272. long htol __ARGS((char *));
  273. char *inbuf __ARGS((int16 port,char *buf,int16 cnt));
  274. int16 hash_ip __ARGS((int32 addr));
  275. int istate __ARGS((void));
  276. void log __ARGS((int s,char *fmt, ...));
  277. void mail_error __ARGS((char *fmt, ...));
  278. int log2 __ARGS((int16 x));
  279. #ifdef UNIX
  280. #define ltop(l) ((void *) (l))
  281. #else
  282. void *ltop __ARGS((long));
  283. #endif
  284. void *mallocw __ARGS((unsigned nb));
  285. char *outbuf __ARGS((int16 port,char *buf,int16 cnt));
  286. #ifdef UNIX
  287. #define ptol(p) ((long)(p))
  288. #else
  289. long ptol __ARGS((void *));
  290. #endif
  291. void restore __ARGS((int));
  292. void rflush __ARGS((void));
  293. void rip __ARGS((char *));
  294. char *smsg __ARGS((char *msgs[],unsigned nmsgs,unsigned n));
  295. int tprintf __ARGS((char *fmt,...))
  296. #ifdef __GNUC__
  297.     __attribute__ ((format (printf, 1, 2)))
  298. #endif
  299.     ;
  300. #if     !defined __TURBOC__
  301. char *strdup __ARGS((const char *));
  302. #endif
  303. int wildmat __ARGS((char *s,char *p,char **argv));
  304.  
  305. #include <stdlib.h>
  306. #include <string.h>
  307.  
  308. #ifdef UNIX
  309. /* can't do this above, GNU libc defines malloc to gnu_malloc in stdlib.h */
  310. #ifdef malloc
  311. #undef malloc
  312. #endif
  313. #define malloc mallocw
  314. #endif
  315.  
  316. #ifdef  AZTEC
  317. #define rewind(fp)      fseek(fp,0L,0);
  318. #endif
  319.  
  320. #if     defined(__TURBOC__) && defined(MSDOS)
  321. #define movblock(so,ss,do,ds,c) movedata(ss,so,ds,do,c)
  322. #ifndef outportw
  323. #define outportw outport
  324. #endif
  325. #ifndef inportw
  326. #define inportw inport
  327. #endif
  328.  
  329. #else
  330.  
  331. /* General purpose function macros already defined in turbo C */
  332. #ifndef min
  333. #define min(x,y)        ((x)<(y)?(x):(y))       /* Lesser of two args */
  334. #endif
  335. #ifndef max
  336. #define max(x,y)        ((x)>(y)?(x):(y))       /* Greater of two args */
  337. #endif
  338. #ifdef  MSDOS
  339. #define MK_FP(seg,ofs)  ((void far *) \
  340.             (((unsigned long)(seg) << 16) | (unsigned)(ofs)))
  341. #endif
  342. #endif  /* __TURBOC __ */
  343.  
  344. #ifdef  AMIGA
  345. /* super kludge de WA3YMH */
  346. #ifndef fileno
  347. #include <stdio.h>
  348. #endif
  349. #define fclose(fp)      amiga_fclose(fp)
  350. extern int amiga_fclose __ARGS((FILE *));
  351. extern FILE *tmpfile __ARGS((void));
  352.  
  353. extern char *sys_errlist[];
  354. extern int errno;
  355. #endif
  356.  
  357. /* Externals used by getopt */
  358. extern int optind;
  359. extern char *optarg;
  360.  
  361. #ifndef UNIX
  362. /* Threshold setting on available memory */
  363. extern int32 Memthresh;
  364. #endif
  365.  
  366. /* System clock - count of ticks since startup */
  367. extern int32 Clock;
  368.  
  369. /* Various useful standard error messages */
  370. extern char Badhost[];
  371. extern char Badinterface[];
  372. extern char Existingiface[];
  373. extern char Nospace[];
  374. extern char Notval[];
  375. extern char Version[];
  376. extern char Nosversion[];
  377. extern char *Hostname;
  378.  
  379. /* Your system's end-of-line convention */
  380. extern char Eol[];
  381.  
  382. #ifndef LINUX
  383. extern void (*Gcollect[]) __ARGS((int));
  384. #endif
  385.  
  386. #ifdef UNIX
  387. /* PCs have a few pseudo-"standard" library functions used by NOS */
  388. extern char *stpcpy __ARGS((char *, const char *));
  389. extern char *strlwr __ARGS((char *));
  390. extern char *strupr __ARGS((char *));
  391. extern char *itoa __ARGS((int, char *, int));
  392. #endif
  393.  
  394. /* I know this is cheating, but it definitely makes sure that
  395.  * each module has config.h included ! - WG7J
  396.  */
  397. #ifndef _CONFIG_H
  398. #include "config.h"
  399. #endif
  400.  
  401. #ifdef UNIX
  402. #ifndef _UNIXTM_H
  403. /* this is separate so unix.c can load it without global.h */
  404. #include "unixtm.h"
  405. #endif
  406. #endif
  407.  
  408. /* in main.c  */
  409. void where_outta_here __ARGS((int resetme));
  410.                          
  411. #endif  /* _GLOBAL_H */
  412.